const express = require("express")
const router = express.Router()
const albumDB = require("../../../db/album")

// 获取封面相册
router.get("/imgs",async(req,res)=>{
  try {
    let {type} = req.query
    let doc = null
    if(type==="封面相册"){
      doc =  await albumDB.find({type},{},{
        sort:{
          date:-1
        },
        limit:4
      })
    }else if(type==="动态相册"){
      doc =  await albumDB.find({type},{},{
        sort:{
          date:-1
        },
        limit:5
      })
    }else if(type==="静态相册"){
      doc =  await albumDB.find({type},{},{
        sort:{
          date:-1
        },
      })
    }
    res.send({
      code:0,
      mes:"封面相册",
      data:doc
    })
  } catch (error) {
    res.send({
      code:5,
      mes:"服务器异常，请稍后再试"
    })
  }
})

module.exports = router